#ifndef __NETWORK_PACKET_H
#define __NETWORK_PACKET_H

#include <string>
#include <iostream>
#include <sstream>

#undef DEBUG
#ifdef DEBUG_NETWORKPACKET
#include <iostream>
#define DEBUG(message) std::cout << message << std::endl;
#else
#define DEBUG(message) 
#endif

enum
{
	AM_HUB_ID = 1,
	AM_ALL_NODES = 2,
	AM_NODE_FIRST_ID = 10,
	AM_COMPUTER_ID = 0
};

typedef enum {
	LIGHT_SENSOR = 0,
	LED_COMMAND = 1,

	SET_SAMPLE_INTERVAL = 2,
	/* Sets the samplin interval */

	SET_LIGHT_REPORT_THRESHOLD = 3,
	/* Sets the required threshold to report on a change in the light 
	 * reading */
	 
	BAD_PACKET = 9
	/* A bad packet, typically used if the GameHub recieves an incomplete
	 * packet. Should never be sent from a source, only a relay.
	 */
	 
} packet_type;

/*!
 * \brief NetworkPacket contains the information needed to exchange packets between the motes and base station
 * \author Khalid Alhokail, Vineet Gupta, Oren Melzer, David Schneider
 *
 */
class NetworkPacket
{
public:
	uint8_t type; /* Cast to a packet_type */
	uint8_t destination;
	uint8_t source;
	uint16_t data;

	NetworkPacket() : type(0), data(0), source(0), destination(0){}
	NetworkPacket(uint8_t pType, uint8_t pDestination, uint8_t pSource, uint16_t pData)
		: type(pType), data(pData), source(pSource), destination(pDestination) {}
	NetworkPacket(const char* input);
	
	std::string str() const;
		
private:
	//Parses the data out of an input string, of the type specified by c
	//Returns 0 if data not found
	int dataFromChar(char c, const char* input);
};

std::ostream& operator<<(std::ostream& out, const NetworkPacket& p);

#endif /* __NETWORK_PACKET_H */
